home *** CD-ROM | disk | FTP | other *** search
- /*
- Il server accetta una stringa fino a 256 caratteri sulla porta 4000
- e al rinvia in ordine inverso.
-
- */
-
- if ~show("L","rexxsupport.library") then do
- if ~addlib("rexxsupport.library",0,-30) then do
- say "no rexxsupport.library"
- exit
- end
- end
-
- if ~show("L","rxsocket.library") then do
- if ~addlib("rxsocket.library",0,-30) then do
- say "no rxsocket.library"
- exit
- end
- end
-
- if ~Open("STDERR","*","W") | ~OpenPort("REVSERVPORT") then exit
-
- sock=socket("INET","STREAM","IP")
- if sock<0 then do
- say "Non posso aprire il socket:" Errno()
- exit
- end
-
- local.ADDRFAMILY = "INET"
- local.ADDRADDR = 0
- local.ADDRPORT = 4000
- if bind(sock,"LOCAL")<0 then do
- say "Non posso allocare la porta:" Errno()
- exit
- end
-
- sig = 2**PortSignal("REVSERVPORT")
- SEL.READ.0=sock
- open = 1
- do while open
-
- if Listen(sock,5)<0 then do
- say "Errore Listen():" Errno()
- exit
- end
-
- res = WaitSelect("SEL",,,sig)
-
- pkt = GetPkt("REVSERVPORT")
- if pkt ~= Null() then do
- comm= GetArg(pkt)
- call Reply(pkt)
- if UPPER(comm) == "QUIT" then open = 0
- end
-
- if SEL.0.READ then do
-
- lsock = Accept(sock,"REMOTE")
- if lsock<0 then do
- say "Errore Accept():" Errno()
- exit
- end
-
- len = recv(lsock,"BUF",256)
- if ( len > 0 ) then do
- BUF=Reverse(BUF)
- if send(lsock,BUF) ~= length(BUF) then do
- say "send: error" Errno())
- end
- end
- if ( len < 0 ) & ( errno() ~= 35 )
- then call say "recv: error" Errno()
-
- call CloseSocket(lsock)
-
- end
-
- end
-
- exit
-